package com.hongshu.common.core.enums;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 系统配置键枚举
 */
public enum ConfigKeyEnum {

    // 网站配置
    WEBSITE_LOGO("website.logo", "网站LOGO"),
    WEBSITE_NAME("website.name", "网站名称"),
    WEBSITE_AUTHOR("website.author", "网站作者"),
    WEBSITE_TITLE("website.title", "网站标题"),
    WEBSITE_DESCRIPTION("website.description", "网站描述"),
    WEBSITE_COPYRIGHT("website.copyright", "版权申明"),
    WEBSITE_AI("website.aiUrl", "AI路径"),
    WEBSITE_WECHAT_QR_CODE("website.wechatQrCode", "微信二维码"),
    WEBSITE_ALIPAY_REWARD_QR_CODE("website.alipayRewardQrCode", "支付宝打赏二维码"),
    WEBSITE_WECHAT_REWARD_QR_CODE("website.wechatRewardQrCode", "微信打赏二维码"),
    WEBSITE_FOLLOW_US("website.followUs", "关注我们"),

    // 系统配置
    OSS_TYPE("oss.type", "OSS存储类型"),
    SMS_PRIMARY("sms.primary", "短信服务商优先级"),
    MQ_TYPE("mq.type", "消息队列类型"),
    QUERY_PRIMARY("query.primary", "搜索类型优先级"),
    AMAP_ENABLED("amap.enabled", "高德地图是否启用"),
    BLACKLIST_ENABLED("blacklist.enabled", "黑名单功能开关"),
    CONTENT_AUDIT_ENABLED("content.audit.enabled", "内容审核功能开关"),
    PRODUCT_AUDIT_ENABLED("product.audit.enabled", "商品审核功能开关"),
    USER_AUDIT_ENABLED("user.audit.enabled", "用户审核功能开关"),

    // 本地存储配置
    LOCAL_PICTURE_BASE_URL("local.picture.base.url", "本地文件访问域名"),
    FILE_UPLOAD_PATH("file.upload.path", "文件上传路径"),
    LOCAL_STORAGE_ENABLED("local.storage.enabled", "本地存储是否启用"),

    // 验证码配置
    CAPTCHA_CACHE_TYPE("aj.captcha.cache-type", "验证码缓存类型"),
    CAPTCHA_TYPE("aj.captcha.type", "验证码类型"),
    CAPTCHA_WATER_MARK("aj.captcha.water-mark", "水印文字"),
    CAPTCHA_SLIP_OFFSET("aj.captcha.slip-offset", "滑动拼图误差偏移量"),
    CAPTCHA_AES_STATUS("aj.captcha.aes-status", "AES加密状态"),
    CAPTCHA_INTERFERENCE_OPTIONS("aj.captcha.interference-options", "滑动干扰项"),
    CAPTCHA_JIGSAW("aj.captcha.jigsaw", "滑动图片路径"),
    CAPTCHA_PIC_CLICK("aj.captcha.pic-click", "点击图片路径"),
    CAPTCHA_ENABLED("aj.captcha.enabled", "验证码功能开关"),

    // 高德地图配置
    AMAP_KEY("amap.key", "高德地图key"),
    AMAP_SECURITY_KEY("amap.security-key", "高德地图安全密钥"),

    // 演示账号配置
    DEMO_ACCOUNT_ENABLED("demo.account.enabled", "演示账号功能开关"),
    DEMO_ACCOUNT_USERNAME("demo.account.username", "演示账号用户名"),
    DEMO_ACCOUNT_PASSWORD("demo.account.password", "演示账号密码"),
    DEMO_ACCOUNT_DESCRIPTION("demo.account.description", "演示账号描述"),
    DEMO_ACCOUNT_PERMISSIONS("demo.account.permissions", "演示账号权限范围"),
    DEMO_ACCOUNT_EXPIRE_TIME("demo.account.expireTime", "演示账号有效期"),

    // 演示站配置
    DEMO_SITE_ENABLED("demo.site.enabled", "演示站功能开关"),
    DEMO_SITE_MOBILE_URL("demo.site.mobileUrl", "移动端演示站地址"),
    DEMO_SITE_WEB_URL("demo.site.webUrl", "Web端演示站地址"),
    DEMO_SITE_ADMIN_URL("demo.site.adminUrl", "管理端演示站地址"),
    DEMO_SITE_GITEE_URL("demo.site.giteeUrl", "Gitee项目地址"),
    DEMO_SITE_GITHUB_URL("demo.site.githubUrl", "GitHub项目地址"),
    DEMO_SITE_DOC_URL("demo.site.docUrl", "文档地址"),
    DEMO_SITE_ARCO_ADMIN_URL("demo.site.arcoAdminUrl", "Arco管理端演示站地址"),
    DEMO_SITE_DESCRIPTION("demo.site.description", "演示站描述信息"),
    DEMO_SITE_ENABLE_STATS("demo.site.enableStats", "演示站访问统计开关");


    private final String key;
    private final String description;

    ConfigKeyEnum(String key, String description) {
        this.key = key;
        this.description = description;
    }

    public String getKey() {
        return key;
    }

    public String getDescription() {
        return description;
    }


    /**
     * 根据key获取枚举
     */
    public static ConfigKeyEnum fromKey(String key) {
        for (ConfigKeyEnum configKey : values()) {
            if (configKey.getKey().equals(key)) {
                return configKey;
            }
        }
        return null;
    }

    /**
     * 获取网站配置相关的键
     */
    public static List<String> getWebsiteConfigKeys() {
        return Arrays.stream(values())
                .filter(config -> config.getKey().startsWith("website."))
                .map(ConfigKeyEnum::getKey)
                .collect(Collectors.toList());
    }

    /**
     * 获取系统配置相关的键
     */
//    public static List<String> getSystemConfigKeys() {
//        return Arrays.stream(values())
//                .filter(config -> Arrays.asList("oss.type", "sms.primary", "mq.type",
//                                "query.primary", "amap.enabled", "blacklist.enabled")
//                        .contains(config.getKey()))
//                .map(ConfigKeyEnum::getKey)
//                .collect(Collectors.toList());
//    }
    public static List<String> getSystemConfigKeys() {
        return Arrays.asList(
                OSS_TYPE.getKey(),
                SMS_PRIMARY.getKey(),
                MQ_TYPE.getKey(),
                QUERY_PRIMARY.getKey(),
                AMAP_ENABLED.getKey(),
                BLACKLIST_ENABLED.getKey(),
                CONTENT_AUDIT_ENABLED.getKey(),
                PRODUCT_AUDIT_ENABLED.getKey(),
                USER_AUDIT_ENABLED.getKey()
        );
    }

    /**
     * 获取本地存储配置相关的键
     */
    public static List<String> getLocalConfigKeys() {
        return Arrays.stream(values())
                .filter(config -> config.getKey().startsWith("local.") ||
                        config.getKey().equals("file.upload.path"))
                .map(ConfigKeyEnum::getKey)
                .collect(Collectors.toList());
    }

    /**
     * 获取验证码配置相关的键
     */
    public static List<String> getCaptchaConfigKeys() {
        return Arrays.stream(values())
                .filter(config -> config.getKey().startsWith("aj.captcha."))
                .map(ConfigKeyEnum::getKey)
                .collect(Collectors.toList());
    }

    /**
     * 获取高德地图配置相关的键
     */
    public static List<String> getAmapConfigKeys() {
        return Arrays.stream(values())
                .filter(config -> config.getKey().startsWith("amap."))
                .map(ConfigKeyEnum::getKey)
                .collect(Collectors.toList());
    }

    /**
     * 获取演示账号配置相关的键
     */
    public static List<String> getDemoAccountConfigKeys() {
        return Arrays.stream(values())
                .filter(config -> config.getKey().startsWith("demo.account."))
                .map(ConfigKeyEnum::getKey)
                .collect(Collectors.toList());
    }

    /**
     * 获取演示站配置相关的键
     */
    public static List<String> getDemoSiteConfigKeys() {
        return Arrays.stream(values())
                .filter(config -> config.getKey().startsWith("demo.site."))
                .map(ConfigKeyEnum::getKey)
                .collect(Collectors.toList());
    }
}
